/** */
package co.com.umobile.persistence;

import android.accounts.Account;
import android.content.ContentResolver;
import android.net.Uri;

/**
 * @author sergiogranada
 * 
 */
public class ProviderUtilities {

	/** ACCOUNT_TYPE. */
	public static final String ACCOUNT_TYPE = "co.com.umobile";

	/** AUTHTOKEN_TYPE. */
	public static final String AUTHTOKEN_TYPE = "co.com.umobile";

	/** SUBJECT_AUTHORITY. */
	public static final String SUBJECT_AUTORITY = "co.com.umobile.service.SubjectProvider";

	/** ITEM_AUTORITY. */
	public static final String PLACE_AUTORITY = "co.com.umobile.service.PlaceProvider";

	/** SUBJECT_AUTHORITY. */
	public static final String SUBJECT_DETAIL_AUTORITY = "co.com.umobile.service.SubjectDetailProvider";

	/** ITEM_AUTORITY. */
	public static final String NOTIFICATION_AUTORITY = "co.com.umobile.service.NotificationProvider";

	/** CONTENT_URI_SUBJECT. */
	public static final Uri CONTENT_URI_SUBJECT = Uri.parse("content://" + SUBJECT_AUTORITY + "/subjectList");

	/** CONTENT_URI_PLACE. */
	public static final Uri CONTENT_URI_PLACE = Uri.parse("content://" + PLACE_AUTORITY + "/placeList");

	/** CONTENT_URI_SUBJECT. */
	public static final Uri CONTENT_URI_SUBJECT_DETAIL = Uri.parse("content://" + SUBJECT_DETAIL_AUTORITY
			+ "/subjectDetailList");

	/** CONTENT_URI_PLACE. */
	public static final Uri CONTENT_URI_NOTIFICATION = Uri.parse("content://" + NOTIFICATION_AUTORITY
			+ "/notificationList");

	/**
	 * returns the uri related to the service code.
	 * 
	 * @param serviceCode
	 *            serviceCode.
	 * @return Uri uri.
	 */
	public static Uri getUriByServiceCode(int serviceCode) {

		switch (serviceCode) {

		case 0:
			return CONTENT_URI_SUBJECT;
		case 1:
			return CONTENT_URI_PLACE;
		case 2:
			return CONTENT_URI_SUBJECT_DETAIL;
		case 3:
			return CONTENT_URI_NOTIFICATION;
		default:
			return null;
		}
	}

	/**
	 * used by the sync adapter to subscribe a service (!!! important >> call this method after subscribe an account)
	 * 
	 * @param account
	 *            account.
	 * @param authority
	 *            authority.
	 * @param sync
	 *            sync.
	 */
	public static void setSyncPropertiesByProvider(Account account, String authority, boolean sync) {

		ContentResolver.setSyncAutomatically(account, authority, sync);
		ContentResolver.setIsSyncable(account, authority, 1);

	}

}
